package cmd

import (
	"gitee.com/kmyss/gf-ex/yscmd"
	"gitee.com/kmyss/gf-ex/yslog"
	"gitee.com/kmyss/gf-ex/ysutils/ysfile"
	"github.com/gogf/gf/os/gcmd"
)

type RootBuilder struct {
	yscmd.CommandBuilderCore
}

func (b *RootBuilder) Init() {
	// 初始化一些中间参数

	b.C = yscmd.NewCommandWithDifaultFunc()
	b.C.Use = "YSDefaultCmd"
	b.C.Run = b.run
	b.C.Help = b.help
	b.addCmd()
	b.addFlag()
}

func (b *RootBuilder) addCmd() {
	yscmd.SetDefaultCommand(b)
}

func (b *RootBuilder) addFlag() {
	yscmd.SetDefaultFlag(b)
}

func (b *RootBuilder) run(c *yscmd.Command) {
	yslog.Debug("进入调试模式")
	ysfile.DebugConfig()

	cmdName := gcmd.GetArg(1)
	b.C.RunChildCmd(cmdName)
}

func (b RootBuilder) help(c *yscmd.Command) {
	c.PrintHelp()
}
